#-*-coding:utf-8-*-
__author__ = 'luv'

import get_conn

#stuinfo.py 没有连接数据库表，get_conn
#根据学号返回姓名
def find_name(stuid):
    conn = get_conn.get_conn()
    cur = conn.cursor()
    SQL = "SELECT Name FROM stuinfo WHERE StuID =" + str(stuid) +" LIMIT 1"
    cur.execute(SQL)
    r = cur.fetchone()
    cur.close()
    conn.close()
    return  r[0]

#根据姓名返回学号
def find_stuid(name):
    conn = get_conn.get_conn()
    cur = conn.cursor()
    SQL = "SELECT * FROM biding WHERE Name = '" + name + "'" + "LIMIT 1"
    cur.execute(SQL)
    r = cur.fetchone()
    cur.close()
    conn.close()
    return  r[0]

#根据学号返回其他信息
def find_info(stuid):
    conn = get_conn.get_conn()
    cur = conn.cursor()
    SQL = "SELECT * FROM stuinfo WHERE StuID =" + str(stuid)
    cur.execute(SQL)
    r = cur.fetchone()
    cur.close()
    conn.close()
    return  r

def find_one(SQL):
    conn = get_conn.get_conn()
    cur = conn.cursor()
    cur.execute(SQL)
    r = cur.fetchone()
    cur.close()
    conn.close()
    return  r
def find_all(SQL):
    conn = get_conn.get_conn()
    cur = conn.cursor()
    cur.execute(SQL)
    r = cur.fetchall()
    cur.close()
    conn.close()
    return  r

#modified by aesop
#根据班级获取学生学号和姓名
def find_stu_by_class(class_number):
    SQL = "SELECT StuID,Name FROM stuinfo WHERE stuinfo.Class = " + class_number
    return find_all(SQL)

def find_all_stu():
    SQL = "SELECT StuID,Name FROM stuinfo"
    return find_all(SQL)

def find_stu_by_grade(grade):
    SQL = "SELECT StuID,Name FROM stuinfo WHERE stuinfo.Class LIKE \"%s%%\"" % grade
    return find_all(SQL)

# print find_name('121270026')
